package com.soft.javase.ch09.set;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/6
 */
public class User implements Comparable<User>{
    @Override
    public int compareTo(User o) {
        //按照年龄升序进行排序，若年龄相同则按照姓名的降序进行排列
        if(this.age==o.age){
            return o.username.compareTo(this.username);
        }
        return this.age-o.age;
    }

    private String username;
    private int age;


    public User() {
    }

    public User(String username, int age) {
        this.username = username;
        this.age = age;
    }

    /**
     * 获取
     * @return username
     */
    public String getUsername() {
        return username;
    }

    /**
     * 设置
     * @param username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "User{username = " + username + ", age = " + age + "}";
    }
}
